package com.numberone.master.modules.card.service;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.numberone.master.common.exception.BizException;
import com.numberone.master.common.menu.RespCode;
import com.numberone.master.common.persistence.Page;
import com.numberone.master.common.service.CrudService;
import com.numberone.master.common.utils.StringUtils;
import com.numberone.master.modules.card.entity.CardAmount;
import com.numberone.master.modules.card.dao.CardAmountDao;

/**
 * 流量卡余额Service
 * @author ck
 * @version 2018-07-11
 */
@Service
@Transactional(readOnly = true)
public class CardAmountService extends CrudService<CardAmountDao, CardAmount> {
	
	@Autowired
	private CardAmountDao cardAmountDao;

	public CardAmount get(String id) {
		return super.get(id);
	}
	
	
	@Transactional(readOnly = false)
	public void subtractAmount(String iccid,Double availableAmount,Double iccfreezingAmount) {
		if(StringUtils.isBlank(iccid)){
			throw new BizException(RespCode.NOT_PARAM_ERROR);
		}
		 cardAmountDao.subtractAmount(iccid,availableAmount,iccfreezingAmount);
	}
	
	@Transactional(readOnly = false)
	public void addAmount(String iccid,Double availableAmount) {
		if(StringUtils.isBlank(iccid)){
			throw new BizException(RespCode.NOT_PARAM_ERROR);
		}
		 cardAmountDao.addAmount(iccid,availableAmount);
	}
	
	public CardAmount selectCardAmountByIccid(String iccid) {
		if(StringUtils.isBlank(iccid)){
			throw new BizException(RespCode.NOT_PARAM_ERROR);
		}
		return cardAmountDao.selectCardAmountByIccid(iccid);
	}
	
	public List<CardAmount> findList(CardAmount cardAmount) {
		return super.findList(cardAmount);
	}
	
	public Page<CardAmount> findPage(Page<CardAmount> page, CardAmount cardAmount) {
		return super.findPage(page, cardAmount);
	}
	
	@Transactional(readOnly = false)
	public void save(CardAmount cardAmount) {
		super.save(cardAmount);
	}

	@Transactional(readOnly = false)
	public void update(CardAmount cardAmount) {
		super.update(cardAmount);
	}
	
	@Transactional(readOnly = false)
	public void delete(CardAmount cardAmount) {
		super.delete(cardAmount);
	}
	
	@Transactional(readOnly = false)
	public void updateByIccid(String iccid,Integer autoTopUp){
		cardAmountDao.updateByIccid(iccid,autoTopUp);
	}
}